.class public Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;
.super Ljava/util/concurrent/ThreadPoolExecutor;
.source "MemoryAwareThreadPoolExecutor.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$1;,
        Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;,
        Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$MemoryAwareRunnable;,
        Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$NewThreadRunsPolicy;,
        Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;
    }
.end annotation


# static fields
.field private static final logger:Lorg/jboss/netty/logging/InternalLogger;

.field private static final misuseDetector:Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;


# instance fields
.field private final channelCounters:Ljava/util/concurrent/ConcurrentMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/concurrent/ConcurrentMap",
            "<",
            "Lorg/jboss/netty/channel/Channel;",
            "Ljava/util/concurrent/atomic/AtomicLong;",
            ">;"
        }
    .end annotation
.end field

.field private volatile settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

.field private final totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .prologue
    .line 135
    const-class v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;

    invoke-static {v0}, Lorg/jboss/netty/logging/InternalLoggerFactory;->getInstance(Ljava/lang/Class;)Lorg/jboss/netty/logging/InternalLogger;

    move-result-object v0

    sput-object v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->logger:Lorg/jboss/netty/logging/InternalLogger;

    .line 138
    new-instance v0, Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;

    const-class v1, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;

    invoke-direct {v0, v1}, Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;-><init>(Ljava/lang/Class;)V

    sput-object v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->misuseDetector:Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;

    return-void
.end method

.method public constructor <init>(IJJ)V
    .locals 9
    .parameter "corePoolSize"
    .parameter "maxChannelMemorySize"
    .parameter "maxTotalMemorySize"

    .prologue
    .line 159
    const-wide/16 v6, 0x1e

    sget-object v8, Ljava/util/concurrent/TimeUnit;->SECONDS:Ljava/util/concurrent/TimeUnit;

    move-object v0, p0

    move v1, p1

    move-wide v2, p2

    move-wide v4, p4

    invoke-direct/range {v0 .. v8}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;-><init>(IJJJLjava/util/concurrent/TimeUnit;)V

    .line 160
    return-void
.end method

.method public constructor <init>(IJJJLjava/util/concurrent/TimeUnit;)V
    .locals 10
    .parameter "corePoolSize"
    .parameter "maxChannelMemorySize"
    .parameter "maxTotalMemorySize"
    .parameter "keepAliveTime"
    .parameter "unit"

    .prologue
    .line 177
    invoke-static {}, Ljava/util/concurrent/Executors;->defaultThreadFactory()Ljava/util/concurrent/ThreadFactory;

    move-result-object v9

    move-object v0, p0

    move v1, p1

    move-wide v2, p2

    move-wide v4, p4

    move-wide/from16 v6, p6

    move-object/from16 v8, p8

    invoke-direct/range {v0 .. v9}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;-><init>(IJJJLjava/util/concurrent/TimeUnit;Ljava/util/concurrent/ThreadFactory;)V

    .line 178
    return-void
.end method

.method public constructor <init>(IJJJLjava/util/concurrent/TimeUnit;Ljava/util/concurrent/ThreadFactory;)V
    .locals 11
    .parameter "corePoolSize"
    .parameter "maxChannelMemorySize"
    .parameter "maxTotalMemorySize"
    .parameter "keepAliveTime"
    .parameter "unit"
    .parameter "threadFactory"

    .prologue
    .line 196
    new-instance v9, Lorg/jboss/netty/util/DefaultObjectSizeEstimator;

    invoke-direct {v9}, Lorg/jboss/netty/util/DefaultObjectSizeEstimator;-><init>()V

    move-object v0, p0

    move v1, p1

    move-wide v2, p2

    move-wide v4, p4

    move-wide/from16 v6, p6

    move-object/from16 v8, p8

    move-object/from16 v10, p9

    invoke-direct/range {v0 .. v10}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;-><init>(IJJJLjava/util/concurrent/TimeUnit;Lorg/jboss/netty/util/ObjectSizeEstimator;Ljava/util/concurrent/ThreadFactory;)V

    .line 197
    return-void
.end method

.method public constructor <init>(IJJJLjava/util/concurrent/TimeUnit;Lorg/jboss/netty/util/ObjectSizeEstimator;Ljava/util/concurrent/ThreadFactory;)V
    .locals 14
    .parameter "corePoolSize"
    .parameter "maxChannelMemorySize"
    .parameter "maxTotalMemorySize"
    .parameter "keepAliveTime"
    .parameter "unit"
    .parameter "objectSizeEstimator"
    .parameter "threadFactory"

    .prologue
    .line 217
    const-class v3, Ljava/lang/Runnable;

    invoke-static {v3}, Lorg/jboss/netty/util/internal/QueueFactory;->createQueue(Ljava/lang/Class;)Ljava/util/concurrent/BlockingQueue;

    move-result-object v9

    new-instance v11, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$NewThreadRunsPolicy;

    const/4 v3, 0x0

    invoke-direct {v11, v3}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$NewThreadRunsPolicy;-><init>(Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$1;)V

    move-object v3, p0

    move v4, p1

    move v5, p1

    move-wide/from16 v6, p6

    move-object/from16 v8, p8

    move-object/from16 v10, p10

    invoke-direct/range {v3 .. v11}, Ljava/util/concurrent/ThreadPoolExecutor;-><init>(IIJLjava/util/concurrent/TimeUnit;Ljava/util/concurrent/BlockingQueue;Ljava/util/concurrent/ThreadFactory;Ljava/util/concurrent/RejectedExecutionHandler;)V

    .line 143
    new-instance v3, Lorg/jboss/netty/util/internal/ConcurrentIdentityHashMap;

    invoke-direct {v3}, Lorg/jboss/netty/util/internal/ConcurrentIdentityHashMap;-><init>()V

    iput-object v3, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->channelCounters:Ljava/util/concurrent/ConcurrentMap;

    .line 220
    if-nez p9, :cond_0

    .line 221
    new-instance v3, Ljava/lang/NullPointerException;

    const-string v4, "objectSizeEstimator"

    invoke-direct {v3, v4}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V

    throw v3

    .line 223
    :cond_0
    const-wide/16 v3, 0x0

    cmp-long v3, p2, v3

    if-gez v3, :cond_1

    .line 224
    new-instance v3, Ljava/lang/IllegalArgumentException;

    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    const-string v5, "maxChannelMemorySize: "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    move-wide/from16 v0, p2

    invoke-virtual {v4, v0, v1}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v3

    .line 227
    :cond_1
    const-wide/16 v3, 0x0

    cmp-long v3, p4, v3

    if-gez v3, :cond_2

    .line 228
    new-instance v3, Ljava/lang/IllegalArgumentException;

    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    const-string v5, "maxTotalMemorySize: "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    move-wide/from16 v0, p4

    invoke-virtual {v4, v0, v1}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v3

    .line 235
    :cond_2
    :try_start_0
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v3

    const-string v4, "allowCoreThreadTimeOut"

    const/4 v5, 0x1

    new-array v5, v5, [Ljava/lang/Class;

    const/4 v6, 0x0

    sget-object v7, Ljava/lang/Boolean;->TYPE:Ljava/lang/Class;

    aput-object v7, v5, v6

    invoke-virtual {v3, v4, v5}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;

    move-result-object v12

    .line 236
    .local v12, m:Ljava/lang/reflect/Method;
    const/4 v3, 0x1

    new-array v3, v3, [Ljava/lang/Object;

    const/4 v4, 0x0

    sget-object v5, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean;

    aput-object v5, v3, v4

    invoke-virtual {v12, p0, v3}, Ljava/lang/reflect/Method;->invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0

    .line 244
    .end local v12           #m:Ljava/lang/reflect/Method;
    :goto_0
    new-instance v3, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    move-object/from16 v0, p9

    move-wide/from16 v1, p2

    invoke-direct {v3, v0, v1, v2}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;-><init>(Lorg/jboss/netty/util/ObjectSizeEstimator;J)V

    iput-object v3, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    .line 247
    const-wide/16 v3, 0x0

    cmp-long v3, p4, v3

    if-nez v3, :cond_3

    .line 248
    const/4 v3, 0x0

    iput-object v3, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    .line 254
    :goto_1
    sget-object v3, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->misuseDetector:Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;

    invoke-virtual {v3}, Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;->increase()V

    .line 255
    return-void

    .line 237
    :catch_0
    move-exception v13

    .line 239
    .local v13, t:Ljava/lang/Throwable;
    sget-object v3, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->logger:Lorg/jboss/netty/logging/InternalLogger;

    const-string v4, "ThreadPoolExecutor.allowCoreThreadTimeOut() is not supported in this platform."

    invoke-interface {v3, v4}, Lorg/jboss/netty/logging/InternalLogger;->debug(Ljava/lang/String;)V

    goto :goto_0

    .line 250
    .end local v13           #t:Ljava/lang/Throwable;
    :cond_3
    new-instance v3, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    move-wide/from16 v0, p4

    invoke-direct {v3, v0, v1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;-><init>(J)V

    iput-object v3, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    goto :goto_1
.end method

.method private getChannelCounter(Lorg/jboss/netty/channel/Channel;)Ljava/util/concurrent/atomic/AtomicLong;
    .locals 3
    .parameter "channel"

    .prologue
    .line 451
    iget-object v2, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->channelCounters:Ljava/util/concurrent/ConcurrentMap;

    invoke-interface {v2, p1}, Ljava/util/concurrent/ConcurrentMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/concurrent/atomic/AtomicLong;

    .line 452
    .local v0, counter:Ljava/util/concurrent/atomic/AtomicLong;
    if-nez v0, :cond_0

    .line 453
    new-instance v0, Ljava/util/concurrent/atomic/AtomicLong;

    .end local v0           #counter:Ljava/util/concurrent/atomic/AtomicLong;
    invoke-direct {v0}, Ljava/util/concurrent/atomic/AtomicLong;-><init>()V

    .line 454
    .restart local v0       #counter:Ljava/util/concurrent/atomic/AtomicLong;
    iget-object v2, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->channelCounters:Ljava/util/concurrent/ConcurrentMap;

    invoke-interface {v2, p1, v0}, Ljava/util/concurrent/ConcurrentMap;->putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/util/concurrent/atomic/AtomicLong;

    .line 455
    .local v1, oldCounter:Ljava/util/concurrent/atomic/AtomicLong;
    if-eqz v1, :cond_0

    .line 456
    move-object v0, v1

    .line 461
    .end local v1           #oldCounter:Ljava/util/concurrent/atomic/AtomicLong;
    :cond_0
    invoke-interface {p1}, Lorg/jboss/netty/channel/Channel;->isOpen()Z

    move-result v2

    if-nez v2, :cond_1

    .line 462
    iget-object v2, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->channelCounters:Ljava/util/concurrent/ConcurrentMap;

    invoke-interface {v2, p1}, Ljava/util/concurrent/ConcurrentMap;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 464
    :cond_1
    return-object v0
.end method


# virtual methods
.method protected beforeExecute(Ljava/lang/Thread;Ljava/lang/Runnable;)V
    .locals 0
    .parameter "t"
    .parameter "r"

    .prologue
    .line 372
    invoke-super {p0, p1, p2}, Ljava/util/concurrent/ThreadPoolExecutor;->beforeExecute(Ljava/lang/Thread;Ljava/lang/Runnable;)V

    .line 373
    invoke-virtual {p0, p2}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->decreaseCounter(Ljava/lang/Runnable;)V

    .line 374
    return-void
.end method

.method protected decreaseCounter(Ljava/lang/Runnable;)V
    .locals 12
    .parameter "task"

    .prologue
    .line 413
    invoke-virtual {p0, p1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->shouldCount(Ljava/lang/Runnable;)Z

    move-result v9

    if-nez v9, :cond_1

    .line 448
    :cond_0
    :goto_0
    return-void

    .line 417
    :cond_1
    iget-object v8, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    .line 418
    .local v8, settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;
    iget-wide v6, v8, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;->maxChannelMemorySize:J

    .line 421
    .local v6, maxChannelMemorySize:J
    instance-of v9, p1, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;

    if-eqz v9, :cond_4

    move-object v9, p1

    .line 422
    check-cast v9, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;

    iget v5, v9, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;->estimatedSize:I

    .line 427
    .local v5, increment:I
    :goto_1
    iget-object v9, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    if-eqz v9, :cond_2

    .line 428
    iget-object v9, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    int-to-long v10, v5

    invoke-virtual {v9, v10, v11}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;->decrease(J)V

    .line 431
    :cond_2
    instance-of v9, p1, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;

    if-eqz v9, :cond_0

    move-object v4, p1

    .line 432
    check-cast v4, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;

    .line 433
    .local v4, eventTask:Lorg/jboss/netty/handler/execution/ChannelEventRunnable;
    invoke-virtual {v4}, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;->getEvent()Lorg/jboss/netty/channel/ChannelEvent;

    move-result-object v9

    invoke-interface {v9}, Lorg/jboss/netty/channel/ChannelEvent;->getChannel()Lorg/jboss/netty/channel/Channel;

    move-result-object v0

    .line 434
    .local v0, channel:Lorg/jboss/netty/channel/Channel;
    invoke-direct {p0, v0}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->getChannelCounter(Lorg/jboss/netty/channel/Channel;)Ljava/util/concurrent/atomic/AtomicLong;

    move-result-object v9

    neg-int v10, v5

    int-to-long v10, v10

    invoke-virtual {v9, v10, v11}, Ljava/util/concurrent/atomic/AtomicLong;->addAndGet(J)J

    move-result-wide v1

    .line 436
    .local v1, channelCounter:J
    const-wide/16 v9, 0x0

    cmp-long v9, v6, v9

    if-eqz v9, :cond_0

    cmp-long v9, v1, v6

    if-gez v9, :cond_0

    invoke-interface {v0}, Lorg/jboss/netty/channel/Channel;->isOpen()Z

    move-result v9

    if-eqz v9, :cond_0

    .line 437
    invoke-interface {v0}, Lorg/jboss/netty/channel/Channel;->isReadable()Z

    move-result v9

    if-nez v9, :cond_0

    .line 439
    invoke-virtual {v4}, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;->getContext()Lorg/jboss/netty/channel/ChannelHandlerContext;

    move-result-object v3

    .line 440
    .local v3, ctx:Lorg/jboss/netty/channel/ChannelHandlerContext;
    invoke-interface {v3}, Lorg/jboss/netty/channel/ChannelHandlerContext;->getHandler()Lorg/jboss/netty/channel/ChannelHandler;

    move-result-object v9

    instance-of v9, v9, Lorg/jboss/netty/handler/execution/ExecutionHandler;

    if-eqz v9, :cond_3

    .line 442
    const/4 v9, 0x0

    invoke-interface {v3, v9}, Lorg/jboss/netty/channel/ChannelHandlerContext;->setAttachment(Ljava/lang/Object;)V

    .line 444
    :cond_3
    const/4 v9, 0x1

    invoke-interface {v0, v9}, Lorg/jboss/netty/channel/Channel;->setReadable(Z)Lorg/jboss/netty/channel/ChannelFuture;

    goto :goto_0

    .end local v0           #channel:Lorg/jboss/netty/channel/Channel;
    .end local v1           #channelCounter:J
    .end local v3           #ctx:Lorg/jboss/netty/channel/ChannelHandlerContext;
    .end local v4           #eventTask:Lorg/jboss/netty/handler/execution/ChannelEventRunnable;
    .end local v5           #increment:I
    :cond_4
    move-object v9, p1

    .line 424
    check-cast v9, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$MemoryAwareRunnable;

    iget v5, v9, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$MemoryAwareRunnable;->estimatedSize:I

    .restart local v5       #increment:I
    goto :goto_1
.end method

.method protected doExecute(Ljava/lang/Runnable;)V
    .locals 0
    .parameter "task"

    .prologue
    .line 351
    invoke-virtual {p0, p1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->doUnorderedExecute(Ljava/lang/Runnable;)V

    .line 352
    return-void
.end method

.method protected final doUnorderedExecute(Ljava/lang/Runnable;)V
    .locals 0
    .parameter "task"

    .prologue
    .line 358
    invoke-super {p0, p1}, Ljava/util/concurrent/ThreadPoolExecutor;->execute(Ljava/lang/Runnable;)V

    .line 359
    return-void
.end method

.method public execute(Ljava/lang/Runnable;)V
    .locals 3
    .parameter "command"

    .prologue
    .line 335
    instance-of v1, p1, Lorg/jboss/netty/handler/execution/ChannelDownstreamEventRunnable;

    if-eqz v1, :cond_0

    .line 336
    new-instance v1, Ljava/util/concurrent/RejectedExecutionException;

    const-string v2, "command must be enclosed with an upstream event."

    invoke-direct {v1, v2}, Ljava/util/concurrent/RejectedExecutionException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 338
    :cond_0
    instance-of v1, p1, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;

    if-nez v1, :cond_1

    .line 339
    new-instance v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$MemoryAwareRunnable;

    invoke-direct {v0, p1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$MemoryAwareRunnable;-><init>(Ljava/lang/Runnable;)V

    .end local p1
    .local v0, command:Ljava/lang/Runnable;
    move-object p1, v0

    .line 342
    .end local v0           #command:Ljava/lang/Runnable;
    .restart local p1
    :cond_1
    invoke-virtual {p0, p1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->increaseCounter(Ljava/lang/Runnable;)V

    .line 343
    invoke-virtual {p0, p1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->doExecute(Ljava/lang/Runnable;)V

    .line 344
    return-void
.end method

.method public getMaxChannelMemorySize()J
    .locals 2

    .prologue
    .line 287
    iget-object v0, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    iget-wide v0, v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;->maxChannelMemorySize:J

    return-wide v0
.end method

.method public getMaxTotalMemorySize()J
    .locals 2

    .prologue
    .line 314
    iget-object v0, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    iget-wide v0, v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;->limit:J

    return-wide v0
.end method

.method public getObjectSizeEstimator()Lorg/jboss/netty/util/ObjectSizeEstimator;
    .locals 1

    .prologue
    .line 267
    iget-object v0, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    iget-object v0, v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;->objectSizeEstimator:Lorg/jboss/netty/util/ObjectSizeEstimator;

    return-object v0
.end method

.method protected increaseCounter(Ljava/lang/Runnable;)V
    .locals 12
    .parameter "task"

    .prologue
    .line 377
    invoke-virtual {p0, p1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->shouldCount(Ljava/lang/Runnable;)Z

    move-result v9

    if-nez v9, :cond_1

    .line 410
    .end local p1
    :cond_0
    :goto_0
    return-void

    .line 381
    .restart local p1
    :cond_1
    iget-object v8, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    .line 382
    .local v8, settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;
    iget-wide v6, v8, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;->maxChannelMemorySize:J

    .line 384
    .local v6, maxChannelMemorySize:J
    iget-object v9, v8, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;->objectSizeEstimator:Lorg/jboss/netty/util/ObjectSizeEstimator;

    invoke-interface {v9, p1}, Lorg/jboss/netty/util/ObjectSizeEstimator;->estimateSize(Ljava/lang/Object;)I

    move-result v5

    .line 386
    .local v5, increment:I
    instance-of v9, p1, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;

    if-eqz v9, :cond_4

    move-object v4, p1

    .line 387
    check-cast v4, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;

    .line 388
    .local v4, eventTask:Lorg/jboss/netty/handler/execution/ChannelEventRunnable;
    iput v5, v4, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;->estimatedSize:I

    .line 389
    invoke-virtual {v4}, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;->getEvent()Lorg/jboss/netty/channel/ChannelEvent;

    move-result-object v9

    invoke-interface {v9}, Lorg/jboss/netty/channel/ChannelEvent;->getChannel()Lorg/jboss/netty/channel/Channel;

    move-result-object v0

    .line 390
    .local v0, channel:Lorg/jboss/netty/channel/Channel;
    invoke-direct {p0, v0}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->getChannelCounter(Lorg/jboss/netty/channel/Channel;)Ljava/util/concurrent/atomic/AtomicLong;

    move-result-object v9

    int-to-long v10, v5

    invoke-virtual {v9, v10, v11}, Ljava/util/concurrent/atomic/AtomicLong;->addAndGet(J)J

    move-result-wide v1

    .line 392
    .local v1, channelCounter:J
    const-wide/16 v9, 0x0

    cmp-long v9, v6, v9

    if-eqz v9, :cond_3

    cmp-long v9, v1, v6

    if-ltz v9, :cond_3

    invoke-interface {v0}, Lorg/jboss/netty/channel/Channel;->isOpen()Z

    move-result v9

    if-eqz v9, :cond_3

    .line 393
    invoke-interface {v0}, Lorg/jboss/netty/channel/Channel;->isReadable()Z

    move-result v9

    if-eqz v9, :cond_3

    .line 395
    invoke-virtual {v4}, Lorg/jboss/netty/handler/execution/ChannelEventRunnable;->getContext()Lorg/jboss/netty/channel/ChannelHandlerContext;

    move-result-object v3

    .line 396
    .local v3, ctx:Lorg/jboss/netty/channel/ChannelHandlerContext;
    invoke-interface {v3}, Lorg/jboss/netty/channel/ChannelHandlerContext;->getHandler()Lorg/jboss/netty/channel/ChannelHandler;

    move-result-object v9

    instance-of v9, v9, Lorg/jboss/netty/handler/execution/ExecutionHandler;

    if-eqz v9, :cond_2

    .line 398
    sget-object v9, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean;

    invoke-interface {v3, v9}, Lorg/jboss/netty/channel/ChannelHandlerContext;->setAttachment(Ljava/lang/Object;)V

    .line 400
    :cond_2
    const/4 v9, 0x0

    invoke-interface {v0, v9}, Lorg/jboss/netty/channel/Channel;->setReadable(Z)Lorg/jboss/netty/channel/ChannelFuture;

    .line 407
    .end local v0           #channel:Lorg/jboss/netty/channel/Channel;
    .end local v1           #channelCounter:J
    .end local v3           #ctx:Lorg/jboss/netty/channel/ChannelHandlerContext;
    .end local v4           #eventTask:Lorg/jboss/netty/handler/execution/ChannelEventRunnable;
    .end local p1
    :cond_3
    :goto_1
    iget-object v9, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    if-eqz v9, :cond_0

    .line 408
    iget-object v9, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->totalLimiter:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;

    int-to-long v10, v5

    invoke-virtual {v9, v10, v11}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Limiter;->increase(J)V

    goto :goto_0

    .line 404
    .restart local p1
    :cond_4
    check-cast p1, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$MemoryAwareRunnable;

    .end local p1
    iput v5, p1, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$MemoryAwareRunnable;->estimatedSize:I

    goto :goto_1
.end method

.method public remove(Ljava/lang/Runnable;)Z
    .locals 1
    .parameter "task"

    .prologue
    .line 363
    invoke-super {p0, p1}, Ljava/util/concurrent/ThreadPoolExecutor;->remove(Ljava/lang/Runnable;)Z

    move-result v0

    .line 364
    .local v0, removed:Z
    if-eqz v0, :cond_0

    .line 365
    invoke-virtual {p0, p1}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->decreaseCounter(Ljava/lang/Runnable;)V

    .line 367
    :cond_0
    return v0
.end method

.method public setMaxChannelMemorySize(J)V
    .locals 4
    .parameter "maxChannelMemorySize"

    .prologue
    const-wide/16 v2, 0x0

    .line 295
    cmp-long v0, p1, v2

    if-gez v0, :cond_0

    .line 296
    new-instance v0, Ljava/lang/IllegalArgumentException;

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "maxChannelMemorySize: "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p1, p2}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 300
    :cond_0
    invoke-virtual {p0}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->getTaskCount()J

    move-result-wide v0

    cmp-long v0, v0, v2

    if-lez v0, :cond_1

    .line 301
    new-instance v0, Ljava/lang/IllegalStateException;

    const-string v1, "can\'t be changed after a task is executed"

    invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 305
    :cond_1
    new-instance v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    iget-object v1, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    iget-object v1, v1, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;->objectSizeEstimator:Lorg/jboss/netty/util/ObjectSizeEstimator;

    invoke-direct {v0, v1, p1, p2}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;-><init>(Lorg/jboss/netty/util/ObjectSizeEstimator;J)V

    iput-object v0, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    .line 308
    return-void
.end method

.method public setMaxTotalMemorySize(J)V
    .locals 4
    .parameter "maxTotalMemorySize"
    .annotation runtime Ljava/lang/Deprecated;
    .end annotation

    .prologue
    const-wide/16 v2, 0x0

    .line 322
    cmp-long v0, p1, v2

    if-gez v0, :cond_0

    .line 323
    new-instance v0, Ljava/lang/IllegalArgumentException;

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "maxTotalMemorySize: "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p1, p2}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 327
    :cond_0
    invoke-virtual {p0}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->getTaskCount()J

    move-result-wide v0

    cmp-long v0, v0, v2

    if-lez v0, :cond_1

    .line 328
    new-instance v0, Ljava/lang/IllegalStateException;

    const-string v1, "can\'t be changed after a task is executed"

    invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 331
    :cond_1
    return-void
.end method

.method public setObjectSizeEstimator(Lorg/jboss/netty/util/ObjectSizeEstimator;)V
    .locals 3
    .parameter "objectSizeEstimator"

    .prologue
    .line 274
    if-nez p1, :cond_0

    .line 275
    new-instance v0, Ljava/lang/NullPointerException;

    const-string v1, "objectSizeEstimator"

    invoke-direct {v0, v1}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 278
    :cond_0
    new-instance v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    iget-object v1, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    iget-wide v1, v1, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;->maxChannelMemorySize:J

    invoke-direct {v0, p1, v1, v2}, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;-><init>(Lorg/jboss/netty/util/ObjectSizeEstimator;J)V

    iput-object v0, p0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->settings:Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor$Settings;

    .line 281
    return-void
.end method

.method protected shouldCount(Ljava/lang/Runnable;)Z
    .locals 5
    .parameter "task"

    .prologue
    const/4 v2, 0x0

    .line 474
    instance-of v3, p1, Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;

    if-eqz v3, :cond_2

    move-object v1, p1

    .line 475
    check-cast v1, Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;

    .line 476
    .local v1, r:Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;
    invoke-virtual {v1}, Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;->getEvent()Lorg/jboss/netty/channel/ChannelEvent;

    move-result-object v0

    .line 477
    .local v0, e:Lorg/jboss/netty/channel/ChannelEvent;
    instance-of v3, v0, Lorg/jboss/netty/channel/WriteCompletionEvent;

    if-eqz v3, :cond_1

    .line 485
    .end local v0           #e:Lorg/jboss/netty/channel/ChannelEvent;
    .end local v1           #r:Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;
    :cond_0
    :goto_0
    return v2

    .line 479
    .restart local v0       #e:Lorg/jboss/netty/channel/ChannelEvent;
    .restart local v1       #r:Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;
    :cond_1
    instance-of v3, v0, Lorg/jboss/netty/channel/ChannelStateEvent;

    if-eqz v3, :cond_2

    .line 480
    check-cast v0, Lorg/jboss/netty/channel/ChannelStateEvent;

    .end local v0           #e:Lorg/jboss/netty/channel/ChannelEvent;
    invoke-interface {v0}, Lorg/jboss/netty/channel/ChannelStateEvent;->getState()Lorg/jboss/netty/channel/ChannelState;

    move-result-object v3

    sget-object v4, Lorg/jboss/netty/channel/ChannelState;->INTEREST_OPS:Lorg/jboss/netty/channel/ChannelState;

    if-eq v3, v4, :cond_0

    .line 485
    .end local v1           #r:Lorg/jboss/netty/handler/execution/ChannelUpstreamEventRunnable;
    :cond_2
    const/4 v2, 0x1

    goto :goto_0
.end method

.method protected terminated()V
    .locals 1

    .prologue
    .line 259
    invoke-super {p0}, Ljava/util/concurrent/ThreadPoolExecutor;->terminated()V

    .line 260
    sget-object v0, Lorg/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor;->misuseDetector:Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;

    invoke-virtual {v0}, Lorg/jboss/netty/util/internal/SharedResourceMisuseDetector;->decrease()V

    .line 261
    return-void
.end method
